﻿using System;
using System.Collections.ObjectModel;

using Sunyi.Project.WebPoint.Common;
using Sunyi.Project.WebPoint.Configuration;
using Sunyi.Project.WebPoint.DataContract;
using Sunyi.Project.WebPoint.ServiceAccess;

namespace Sunyi.Project.WebPoint.BusinessLogic
{
    public partial class SystemInfoManager
    {
        public SystemInfo SelectByName(string systemName)
        {
            return controller.SelectByName(systemName);
        }

        public void UploadSystemInfo(SystemInfo systemInfo)
        {
            var roleManager = new RoleManager();
            var roles = roleManager.SelectAll();

            var activeRoles = new Collection<Role>();
            foreach (var role in roles)
            {
                if (role.IsActive) activeRoles.Add(role);
            }

            var systemInfoServiceProxy = new SystemInfoServiceProxy();
            systemInfoServiceProxy.UpdateSystemInfo(systemInfo, activeRoles);
        }

        public int SearchCount(string systemName, bool isActive)
        {
            return controller.SearchCount(systemName, isActive);
        }

        public Collection<SystemInfo> Search(string systemName, bool isActive, int pageIndex, int pageSize)
        {
            return controller.Search(systemName, isActive, pageIndex, pageSize);
        }
    }
}
